Skip to content

Conversation

snitish
Copy link
Member

@snitish snitish commented Nov 23, 2024

>>> input_array=[(1.8816e-09+0j), (3.39676e-09+0j)]
>>> pd.Series(input_array)
0    1.881600e-09+0.000000e+                    00j
1    3.396760e-09+0.000000e+                    00j
dtype: complex128

The issue was due to the regex in the _trim_zeros_complex function not being able to handle +/- in the exponent. It assumes the complex number string to be of the form (-)xxx(+/)yyyj. I fixed the regex so it doesn't split on +/- if preceded by an exponent.
Post the fix:

>>> input_array=[(1.8816e-09+0j), (3.39676e-09+0j)]
>>> pd.Series(input_array)
0    1.881600e-09+0.000000e+00j
1    3.396760e-09+0.000000e+00j
dtype: complex128

@snitish snitish changed the title Fix formatting of complex floats with exponents BUG: Fix formatting of complex floats with exponents Nov 23, 2024
Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Could you also add a whatsnew note in v3.0.0.rst?

)
assert result == expected

# GH #60393
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this a separate test?

@mroeschke mroeschke added the Output-Formatting __repr__ of pandas objects, to_string label Nov 25, 2024
@snitish snitish closed this Nov 25, 2024
@snitish
Copy link
Member Author

snitish commented Nov 25, 2024

Looks like I broke my branch. Will re-raise the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Output-Formatting __repr__ of pandas objects, to_string

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Printing of a pandas Series of complex numbers with e-notation has broken between 2.0.x and older versions and the newer 2.1.x, 2.2.x versions

5 participants